package java8.deom4;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;



import org.junit.Test;

import java8.bean.Artist;

public class Tests1  {

	List<Artist> allArtists=new ArrayList<>() ;


	
	private void init() {
		allArtists.add(new Artist("Artist_a","a","guangzhou"));
		allArtists.add(new Artist("Artist_b","b","foshan"));
		allArtists.add(new Artist("Artist_c","c","shenzhen"));
		

	}
	
	
	@Test
	public void test1() {
		init();
		long count=allArtists.stream().filter(
				artist -> artist.getOrigin().equals("foshan"))
				.count();
		System.out.println(count);
	}
	
	@Test
	public void test2() {
		init();
		Predicate<Artist> predicate= artist -> artist.getOrigin().equals("foshan");
//		Predicate<Artist> predicate2= (Artist artist) -> artist.getOrigin().equals("foshan");
		Stream<Artist> streamList=allArtists.stream();
//		streamList.filter(predicate);
		long count=streamList.filter(predicate).count();
		System.out.println(count);
	}
	
	
	@Test
	public void test3() {
		init();
		//名字不会输出
		allArtists.stream().filter(
				artist -> {
					System. out. println(artist.getName() ) ;
					return artist.getOrigin().equals("foshan");
					});
	}
	
	@Test
	public void test4() {
		init();
		//名字输出,把所有名字打印出来了
		long c=allArtists.stream().filter(
				artist -> {
					System. out. println(artist.getName() ) ;
					return artist.getOrigin().equals("foshan");
					}).count();
		System.out.println(c);
	}
	
	
	
	
	
	
	
	
	
}
